#ifndef ANALYSISRESULT_HPP
#define ANALYSISRESULT_HPP

#include <opencv2/opencv.hpp>
#include <sstream>



class AnalysisResult
{
public:
    cv::Mat bwDigit[2];
    cv::Rect roiDigit[2];
    double property;
    cv::Vec3d location;
public:
    AnalysisResult()
    {

    }

    static cv::Matx22d R2D(double rad)
    {
        return cv::Matx22d(cos(rad), -sin(rad), sin(rad), cos(rad));
    }

    cv::Vec2d ToCarCoordinate(cv::Vec2d pt) const
    {
        return R2D(-location[2])*(pt-cv::Vec2d(location[0], location[1]));
    }

    cv::Vec2d ToWorldCoordinate(cv::Vec2d pt) const
    {
        return R2D(location[2])*pt+cv::Vec2d(location[0], location[1]);
    }

    void Draw(cv::Mat &canvas, double propertyThres=0.1)
    {
        std::ostringstream oss;
        oss<<property;
        if(property>propertyThres)
        {
            cv::rectangle(canvas, roiDigit[0], cv::Scalar(0,0,255), 5);
            cv::rectangle(canvas, roiDigit[1], cv::Scalar(0,255,0), 5);
            oss<<"  "<<location;
        }
        std::string res=oss.str();
        cv::putText(canvas, res, cv::Point(0,canvas.rows-1),cv::FONT_HERSHEY_SIMPLEX,2.6,cv::Scalar(0,0,255),2);
    }

    void DrawFollow(cv::Mat &canvas, double propertyThres=0.1)
    {
        std::string text = "Follow!";
        int font_face = cv::FONT_HERSHEY_COMPLEX;
        double font_scale = 10;
        int thickness = 10;
        int baseline;

        cv::Size text_size = cv::getTextSize(text, font_face, font_scale, thickness, &baseline);

        cv::Point origin;
        origin.x = canvas.cols / 2 - text_size.width / 2;
        origin.y = canvas.rows / 2 + text_size.height / 2;
        cv::putText(canvas, text, origin, font_face, font_scale, cv::Scalar(0, 255, 0), thickness, 8, 0);

    }

    void DrawNotFollow(cv::Mat &canvas, double propertyThres=0.1)
    {
//        std::ostringstream oss;
//        oss<<property;
//        if(property>propertyThres)
//        {
//            cv::rectangle(canvas, cv::Rect(20,20,20,20), cv::Scalar(0,255,255), -1);
//            cv::rectangle(canvas, roiDigit[1], cv::Scalar(0,255,0), 5);
//            oss<<"  "<<location;
//        }
//        std::string res=oss.str();
        std::string text = "Not Follow!";
        int font_face = cv::FONT_HERSHEY_COMPLEX;
        double font_scale = 10;
        int thickness = 10;
        int baseline;

        cv::Size text_size = cv::getTextSize(text, font_face, font_scale, thickness, &baseline);

        cv::Point origin;
        origin.x = canvas.cols / 2 - text_size.width / 2;
        origin.y = canvas.rows / 2 + text_size.height / 2;
        cv::putText(canvas, text, origin, font_face, font_scale, cv::Scalar(0, 0, 255), thickness, 8, 0);

    }



};

#endif // ANALYSISRESULT_HPP

